//
//  MMSClient.cpp
//  MMS
//
//  Created by 王翛然 on 16/8/10.
//  Copyright © 2016年 王翛然. All rights reserved.
//

#include "MMSClient.hpp"

void MMSClient::show()
{
//    std::string name[2], address[2], professional[2];
//    for (int i = 0; i < 2; ++i)
//    {
//        std::cout << "iyoga add-member ";
//        
//        std::cin >> name[i] >> address[i] >> professional[i];
//        Member mem(name[i], address[i], professional[i]);
//        mms.addMember(mem);
//        if (mem.getMemberId() != "-1")
//        {
//            std::cout << "OK." + mem.getMemberName() + "'s member id is " + mem.getMemberId() + ".\n";
//        }
//    }
//
//    std::cout << "iyoga add-card ";
//    std::cout << name[0] << " 年卡\n";
//    mms.addCardToMember(name[0]);
//    
//    std::cout << "iyoga add-card " << name[1] << " 次卡 100\n";
//    mms.addCardToMember(name[1], 100);
    
    std::string order;
    std::string input;
    while (true)
    {
        std::cout << "iyoga ";
        std::getline(std::cin, input);
        std::stringstream in(input);
        in >> order;
        if (order == "add-member")
        {
            addMember(in);
        }
        else if (order == "add-card")
        {
            addCard(in);
        }
        else
        {
            std::cerr << "命令错误，重新输入\n";
        }
    }
}

void MMSClient::addMember(std::stringstream &in)
{
    std::string name, address, professional;
    in >> name >> address >> professional;
    Member mem(name, address, professional);
    mms.addMember(mem);
    if (mem.getMemberId() != "-1")
    {
        std::cout << "OK." + mem.getMemberName() + "'s member id is " +
        mem.getMemberId() + ".\n";
    }
}

void MMSClient::addCard(std::stringstream &in)
{
    std::string name, typeOfCard;
    in >> name >> typeOfCard;
    if (typeOfCard == "年卡")
    {
        mms.addCardToMember(name);
    }
    else if (typeOfCard == "次卡")
    {
        int times = 0;
        in >> times;
        mms.addCardToMember(name, times);
    }
    else
    {
        std::cerr << "命令错误，重新输入\n";
    }
}